package domain

import (
	"gluenet/internal/glue-srvp/domain/aggregate"
	"gluenet/internal/pkg/infra/prepare"
)

// 创建对象，并把对象放入依赖池，架构自动构建依赖
func init() {
	prepare.RegisterService(func() {
		domain := NewOrganizeDomain()
		prepare.InjectDependency(func() *Organize {
			return domain
		})
	})
}

// 物理组织领域，提供关系图谱中的物理拓扑相关服务
type Organize struct {
	InfraTreeFactory *aggregate.InfraTreeFactory
}

// GetTree 查询关系图谱关系树
func (r *Organize) GetTree(organize string) (interface{}, error) {
	return r.InfraTreeFactory.GetTree(organize)
}

// BuildTree 构建关系图谱关系树
func (r *Organize) BuildTree(organize string) error {
	return r.InfraTreeFactory.BuildTree(organize)
}

// CleanTree 清除关系图谱关系树，调试用
func (r *Organize) CleanTree(organize string) error {
	return r.InfraTreeFactory.CleanTree(organize)
}

func NewOrganizeDomain() *Organize {
	domain := &Organize{}
	prepare.FetchDependency(&domain.InfraTreeFactory)
	return domain
}
